/** 
 * 项目名:shiro 
 * 文件名:UserServiceImpl.java 
 * 包名:com.spring.shiro.service.impl 
 * 创建日期:2015年2月13日上午11:12:35 
 * 版权(c): ZTESOFT TECHNOLOGY CO.,LTD.Copyright 2012-2030.All rights reserved
 * 
*/  
  
package com.spring.shiro.service.impl;  

import java.util.Set;

import com.spring.shiro.dao.IUserDao;
import com.spring.shiro.dao.impl.UserDaoImpl;
import com.spring.shiro.helper.PasswordHelper;
import com.spring.shiro.po.User;
import com.spring.shiro.service.IUserService;
 
public class UserServiceImpl implements IUserService {

	private IUserDao userDao = new UserDaoImpl();
    private PasswordHelper passwordHelper = new PasswordHelper();
	
	@Override
	public User createUser(User user) {

		//加密密码
        passwordHelper.encryptPassword(user);
        return userDao.createUser(user);
	}

	@Override
	public void changePassword(Long userId, String newPassword) {
		
		User user =userDao.findOne(userId);
        user.setPassword(newPassword);
        passwordHelper.encryptPassword(user);
        userDao.updateUser(user);
	}

	@Override
	public void correlationRoles(Long userId, Long... roleIds) {
		
		userDao.correlationRoles(userId, roleIds);
	}

	@Override
	public void uncorrelationRoles(Long userId, Long... roleIds) {
		
		userDao.uncorrelationRoles(userId, roleIds);
	}

	@Override
	public User findByUsername(String username) {

		return userDao.findByUsername(username);
	}

	@Override
	public Set<String> findRoles(String username) {

		return userDao.findRoles(username);
	}

	@Override
	public Set<String> findPermissions(String username) {

		return userDao.findPermissions(username);
	}

}
  